<?php

namespace App\Console;

use App\Services\ModifyResourcePriceRecordsService\ModifyResourcePriceRecordsService;
use App\Services\ProductsService\ProductTool;
use App\Services\SourcePicService\SourcePicTool;
use App\Services\Tool\GeneralTool;
use App\Services\Tool\Order\AfterTool;
use App\Services\Tool\Order\OrderTool;
use App\Services\UserService\UserTool;
use App\Services\JPush\JPushService;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
        //待付款超时
        $schedule->call(function () {
            OrderTool::command_order_unpay_to_cancel();
        })->everyFiveMinutes();
        //待付款提醒
        $schedule->call(function () {
            OrderTool::command_order_unpay_remind();
        })->everyFiveMinutes();
        //待收货提醒
        $schedule->call(function () {
            OrderTool::command_order_unsign_remind();
        })->everyFiveMinutes();
        //待收货超时
        $schedule->call(function () {
            OrderTool::command_order_unsign_to_sign();
        })->everyFiveMinutes();
        //关闭订单超时
        $schedule->call(function () {
            OrderTool::command_order_close();
        })->everyFiveMinutes();
        //售后单待收货超时
        $schedule->call(function () {
            AfterTool::command_order_aftermark_sign();
        })->everyFiveMinutes();
        //订单确认提醒
        $schedule->call(function () {
            OrderTool::order_confirm_remind();
        })->hourly();
        //订单确认未发货提醒
        $schedule->call(function () {
            OrderTool::order_unsend_remind();
        })->hourly();
        //消息定时推送
        $schedule->call(function () {
            JPushService::push_timing();
        })->hourly();

        $schedule->call(function () {
            ProductTool::off_the_shelf();
        })->everyFiveMinutes();

        $schedule->call(function () {
            UserTool::checkThirdParty();
        })->daily();

        $schedule->call(function () {
            UserTool::cleanErrorNum();
        })->daily();
        //生成日志并修改日志文件权限
        $schedule->call(function () {
            GeneralTool::generateLog();
        })->dailyAt('00:00');
        //定时修改产品价格
        $schedule->call(function () {
            ModifyResourcePriceRecordsService::modify_product_price();
        })->dailyAt('00:10');

        //定时下架超时素材
        $schedule->call(function () {
            SourcePicTool::sourcePicOffTheShelf();
        })->everyFiveMinutes();

        //后台认证审核超时 修改状态
        $schedule->call(function () {
            UserTool::updateTimeout();
        })->everyThirtyMinutes();

    }

    /**
     * Register the Closure based commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        require base_path('routes/console.php');
    }
}
